package com.android.test;

import java.io.IOException;
import java.io.InputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.util.Log;

public abstract class GameObject
{
	public PointF position;
	public int width, height;
	public Bitmap texture;
	
	public GameObject(PointF position, int width, int height, String imageName, boolean filter)
	{
		this.position = position;
		this.width = width;
		this.height = height;
		
		setImage(imageName, filter);
	}

	public GameObject(PointF position, int width, int height)
	{
		this.position = position;
		this.width = width;
		this.height = height;
	}

	public void draw(Canvas canvas)
	{
		PointF realPosition = new PointF(position.x - (width/2), position.y - (height/2));
		canvas.drawBitmap(texture, realPosition.x, realPosition.y, null);
	}
	
	public void setImage(String imageName, boolean filter) 
	{
		try
		{
			InputStream is = GameLoop.context.getAssets().open(imageName);
			
			Bitmap texture = BitmapFactory.decodeStream(is);
			Bitmap scaledTexture = Bitmap.createScaledBitmap(texture, this.width, this.height, filter);
						
			this.texture = scaledTexture;
		}
		catch(IOException e)
		{
			Log.e(MainActivity.TAG, "Erro carregando imagem");
		}
	}
	
	public PointF setPosition(PointF position)
	{
		this.position = position;
		
		return this.position;
	}
}
